import {
  requst_get_getPicInfo
} from '../../utils/api.js'
var app = getApp();
Page({
  data: {
    TabCur: '',
    categoryList: [],
    photos: [],
    appTips: !0,
    nextStart: 0,
    current: 1,
    pageSize: 20,
    indiacatorDots: false,

  },
  onLoad: function (t) {
    // this.getMenuList(2);
    this.getMenuListNew();
  },
  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {
    this.setData({
        current: 1,
        photos: [],
        isLastPage: !1,
        nextStart: 0,
        loadtext: "到底啦",
        showloadmore: !0
      }),
      this.getPicList(this.data.TabCur);
  },

  appTips: function () {
    wx.setStorageSync("appTips", !0), this.setData({
      appTips: !1
    });
  },
  tabSelect: function (t) {
    var e = t.currentTarget.dataset.id;
    this.setData({
        TabCur: e,
        photos: [],
        current: 1,
        isLastPage: !1,
        nextStart: 0,
        loadtext: "到底啦",
        showloadmore: !0
      }),
      this.getPicList(e);
  },
  goToPhotoInfo: function (t) {
    var e = t.currentTarget.dataset.src;
    var realsrc = t.currentTarget.dataset.realsrc;
    var picid = t.currentTarget.dataset.picid;
    var needcount = app.globalData.downloadPoint;
    console.log(t.currentTarget.dataset)
    console.log(picid)
    if (this.data.TabCur == 0) {
      e = realsrc;
    }
    wx.navigateTo({
      url: "../photo/photo?picId=" +picid + "&src=" + e  + "&needcount=" + needcount,
      success: function (t) {},
      fail: function (t) {},
      complete: function (t) {}
    });
  },

  getPicList: function (picSoneType) {
    var that = this;
    if (picSoneType == 0) {

      const params = {
        picCategory: 2,
        current: that.data.current,
        size: that.data.pageSize
      }
      requst_get_getPicInfo(params).then(res => {
        console.log(res)
        var e = {};
        var picList = res.data.records;
        var picListnew = [];
        for (var i in picList) {
          picListnew.push({
            sid: picList[i].id,
            cid: picList[i].id,
            pic: picList[i].path,
            picReal: picList[i].path
          })
        }
        if (that.data.current == res.data.pages) {
          that.setData({
            isLastPage: !0,
            loadtext: "到底啦",
            showloadmore: !1
          })
        }
        e.photos = that.data.photos.concat(picListnew),
          that.setData(e);
        wx.stopPullDownRefresh();
      }).catch(err => {
        wx.stopPullDownRefresh();
      })
    } else {
      var current = that.data.nextStart
      var url = "https://spare.maibaapp.com/bbs/newUgc/category/info/0/" + picSoneType + "/" + current + "/" + (current + that.data.pageSize)
      wx.request({
        url: url,
        method: "GET",
        success(res) {
          console.log(res.data)
          var e = {};
          var picList = res.data.data.list;
          console.log(picList.length)
          if (picList.length < that.data.pageSize) {
            console.log(picList.length)
            that.setData({

              isLastPage: !0,
              loadtext: "到底啦",
              showloadmore: !1
            })
          }

          e.photos = that.data.photos.concat(picList),
            that.setData(e);
          that.setData({
            nextStart: res.data.data.nextStart
          })

          wx.stopPullDownRefresh();
        }
      })
    }

  },
  //对接别人的头像
  getMenuListNew: function () {
    var that = this
    wx.request({
      url: "https://spare.maibaapp.com/bbs/newUgc/category/list/0",
      method: "GET",
      success(res) {
        console.log(res)
        if (res.data.code == 0) {
          if (res.data.data.categoryList[0]) {
            var menuList = []
            menuList.push({
              cid: 0,
              title: '精选',
              icon: 'aa'
            })
            console.log('version',getApp().globalData.version==1)
            for (var item in res.data.data.categoryList) {
              if(getApp().globalData.version==1&&(res.data.data.categoryList[item].cid=="1"
              ||res.data.data.categoryList[item].cid=="2"
              ||res.data.data.categoryList[item].cid=="3"
              ||res.data.data.categoryList[item].cid=="11"
              ||res.data.data.categoryList[item].cid=="12")){
                
              }else{
              menuList.push(res.data.data.categoryList[item])
              }
            }
            that.setData({
              categoryList: menuList,
              TabCur: 0
            })
            that.getPicList(0)
          }

        } else {
          wx.showToast({
            title: res.data.message,
            icon: 'none'
          })
        }

      }
    })

  },


  getMenuList: function (type) {
    var that = this
    var params = {
      menuType: type
    }
    wx.request({
      url: api.queryMenu,
      method: "POST",
      data: params,
      success(res) {
        console.log(res)
        if (res.data.code == 1) {
          if (res.data.data[0]) {
            that.setData({
              categoryList: res.data.data,
              TabCur: res.data.data[0].id
            })
            that.getPicList(res.data.data[0].id)
          }

        } else {
          wx.showToast({
            title: res.data.message,
            icon: 'none'
          })
        }

      }
    })
  },



  info: function (t) {
    var e = t.currentTarget.dataset.src;
    var needcount = app.globalData.downloadPoint;
    wx.navigateTo({
      url: "../photo/photo?src=" + e + "&needcount=" + needcount+ "&picId=" + picid ,
      success: function (t) {},
      fail: function (t) {},
      complete: function (t) {}
    });
  },
  goTop: function (t) {
    this.setData({
      scrollTop: 0
    }), l = 0, c = null, r.destroy(), r = h({
      id: "recycleId",
      dataKey: "thatItem",
      page: this,
      itemSize: this.itemSizeFunc
    }), this.setData({
      date: d.date
    }), this.getList();
  },
  onReachBottom: function () {
    this.setData({
      current: this.data.current + 1,
    })
    if (!this.data.isLastPage) {
      this.getPicList(this.data.TabCur);
    }
  },

  onShareAppMessage: function () {
    return {
      path: "pages/avatar/avatar",
      title: "每天更新优质头像！",

    };
  }
});